<template>
	<view class="date-range-picker">
		<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
			<view class="input">{{date}}</view>
		</picker>
		<text>至</text>
		<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
			<view class="input">{{date}}</view>
		</picker>
	</view>
</template>

<script>
	export default {
		 name: 'date-range-picker',
		data () {
			const currentDate = this.getDate({
				format: true
			})
			return {
				dateFormat: '',
				// startDate: '',
				// endDate: '',
				date: currentDate,
			}
		},
		 computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			bindDateChange(ev) {
				  this.date = ev.target.value
				console.log(ev)
			},
			 getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}/${month}/${day}`;
			}
		}
	}
</script>

<style lang="scss" >
.date-range-picker {
	display: flex;
	justify-content: space-around;	
	.input {
		height: 50upx;
		padding: 0 25upx;
		line-height:50upx;
		font-size:28upx;
		background:#FFF;
		flex: 1;
	}
}

</style>
